package patternmining.model.graph;

import java.util.Collection;
import java.util.Iterator;
import patternmining.model.construction.SourceDescription;

public class Vertex {

	protected SourceDescription source;
        protected Object identity;

        public Vertex(Object identity){
            this.identity =identity;
            this.source = new SourceDescription();
        }

        public void setSource(SourceDescription source){
            this.source = source;
        }
	/*Varifies if two vertices match by having the same or related types.
         * 
         */ 
        public boolean match(Vertex otherVertex){
            // method trivialy returns true. Override in specific subclasses to match vertices of the same or related type
            // depending on the graph domain
            return otherVertex instanceof Vertex;
        }
        
        public boolean testForSubgraph(Vertex containingGraphVertex, Graph containingGraph, Graph containedGraph){
            boolean isSubgraph = true;
            if(this.match(containingGraphVertex)){
                System.out.println("Map: " + this.toString() + "  -  " + containingGraphVertex.toString() );
                
                Iterator<Edge> outEdges = containedGraph.getOutEdges(this).iterator();
                Edge outEdge;
                while( outEdges.hasNext() ){
                    outEdge = outEdges.next();
                    isSubgraph = isSubgraph & outEdge.testForSubgraph( containingGraphVertex, containingGraph, containedGraph);
                }
                
            }
            return false;
        }
        
}
 
